package com.zhangye.test.api;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.zhangye.test.model.Collapse;
import com.zhangye.test.service.CollapseService;
import com.zhangye.test.service.QiniuService;

@Controller
@RequestMapping("api/collapse")
public class CollapseApi {

	@Autowired
	private CollapseService collapseService;
	@Autowired
	private QiniuService qiniuService;


	/**
	 * IOS崩溃日志
	 * 作者： 张叶
	 * 创建时间：2018年10月17日  下午3:25:50
	 */
	@ResponseBody
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public ApiResult insert(@RequestParam(value = "text", required = false) MultipartFile text) {
		ApiResult result = new ApiResult();
		try {
			String texts = qiniuService.upload("collapse", text.getOriginalFilename(),text.getBytes());
			Collapse c = new Collapse();
			c.setText(texts);
			c.setCreatedAt(new Date());
			collapseService.insert(c);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
}
